<template>

<div id="wrapper">
    <div class="page-search" data-log="搜索页">
        <div class="header">
            <div class="left">
                <a href="/1/#/index" title="小米商城" data-log="HEAD-首页" class="home">
                    <span class="icon-home icon"></span>
                </a>
            </div>
            <div class="tit">
                <div class="searchword"><input autofocus="autofocus"></div>
            </div>
            <div class="searchlabel">
                <a>
                  <router-link :to="{name:'List',query:{searchword:searchword}}">
                    <span class="icon icon-search"></span>
                  </router-link>
                </a>
            </div>
        </div>
        <div>
            <ul class="list-default">
                <li class="top" v-for="hot in hots"><span>{{hot.name}}</span></li>
                <li v-for="recommend in recommends"><span>{{recommend.name}}</span></li>
            </ul>
        </div>
    </div>
</div>
</template>
<script>
  export default {
    data() {
      return {
      hots:[],
      recommends:[],
      }
    },
    created() {
      this.init(); //初始化
    },


    methods: {
      init: function () {
        this.axios.get(`${this.domain}/api/product/search`)
          .then((response) => {
            console.log(response.data);
            this.hots = response.data.hots;
            this.recommends = response.data.recommends;
          });
        var searchword = $.trim($(".searchword input").val());
        // let searchword = this.$route.query.searchword;
        this.axios.get(`${this.domain}/api/product/product_list?searchword=` + searchword,)
          .then((response) => {
            console.log(response.data);
            this.data = response.data;
            // this.recommends = response.data.recommends;
          })
      },

      // function () {
      //   $(".icon-search").click(function () {
      //     alert(222);return;
      //     var searchword = $.trim($(".searchword input").val());
      //     jquery.ajax({
      //       url: `${this.domain}/api/product/product_list?searchword=` + searchword,
      //
      //     });
      //   });
      // }
    }

  }
</script>
